<?php

/**
 * pages actions.
 *
 * @package    shop
 * @subpackage pages
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class pagesActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  private function getViewString($viewName = sfView::SUCCESS) {
        $view = $this->getController()->getView($this->getContext()->getModuleName(), $this->getContext()->getActionName(), $viewName);
        $view->execute();
        $view->getAttributeHolder()->add($this->getVarHolder()->getAll());
        return $view->render();
    } 
    
  public function executeIndex(sfWebRequest $request)
  {

  }
  
  public function executeAjax_product_page(sfWebRequest $request)
  {
      if($request->getParameter('productname') != NULL)
      {
          $product = ProductTable::getInstance()->findOneBy('name', $request->getParameter('productname'));
          $prices = ProductPriceTable::getInstance()->findBy('product_id', $product->getId());
      }
  }
  
  
  public function executeAjax_news_page(sfWebRequest $request)
  {
      $this->news = NewsTable::getInstance()->findOneBy('id', $request->getParameter('id'));
      $array = array("content" => $this->getViewString());
      echo(json_encode($array));
      die;
  }
  
  public function executeAjax_news_list_page(sfWebRequest $request)
  {
      $news = Doctrine_Query::create()->select()->from('news');
      if($request->getParameter('order') != NULL)
      {
          $news->orderBy($request->getParameter('order'));
      }
      if($request->getParameter('limit') != NULL)
      {
          $news->limit($request->getParameter('limit'));
      }
      $this->news = $news->execute();
      $array = array("content" => $this->getViewString());
      echo(json_encode($array));
      die;
  }
  
  public function executeAjax_static_page(sfWebRequest $request)
  {
      $page = PageTable::getInstance()->findOneBy('route', $request->getParameter('subpage'));
      if(!$page)
      {
          $page = new stdClass();
          $page->content = 'Nie odnaleziono strony';
      }
      $array = array("content" => $page->content);
      echo(json_encode($array));
      die;
  }
}
